import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseFilters, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { TypeormFilter } from 'src/common/filters/typeorm.filter';
import { JwtGuard } from 'src/common/guards/jwt.guard';
import { BannerService } from './banner.service';
import { CreateBannerDto } from './dto/create-banner.dto';
import { GetBannerIdentityDto } from './dto/get-banner-identity-dto';
import { GetBannerDto } from './dto/get-banner.dto';
import { UpdateBannerDto } from './dto/update-banner.dto';
import { BannerResultVo } from './vo/banner.result.vo';

@ApiTags('广告')
@Controller('banner')
@UseFilters(new TypeormFilter())
export class BannerController {
  constructor(private readonly bannerService: BannerService) {}

  @Post()
  @ApiOperation({summary:'新增广告'})
  @ApiResponse({type:Number})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  create(@Body() createBannerDto: CreateBannerDto) {
    return this.bannerService.create(createBannerDto);
  }

  @Get()
  @ApiOperation({summary:'广告列表'})
  @ApiResponse({type:BannerResultVo})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  findAll(@Query() query:GetBannerDto) {
    return this.bannerService.findAll(query);
  }

  @Get('user')
  @ApiOperation({summary:'获取广告（博客端）'})
  @ApiResponse({type:BannerResultVo})
  findOneUser(@Query() query:GetBannerIdentityDto) {
    return this.bannerService.findOneIdentity(query);
  }

  @Get(':id')
  @ApiOperation({summary:'获取广告'})
  @ApiResponse({type:BannerResultVo})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  findOne(@Param('id') id: string) {
    return this.bannerService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({summary:'广告修改'})
  @ApiResponse({type:null})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  update(@Param('id') id: string, @Body() updateBannerDto: UpdateBannerDto) {
    return this.bannerService.update(+id, updateBannerDto);
  }

  @Delete(':id')
  @ApiOperation({summary:'广告删除'})
  @ApiResponse({type:null})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  remove(@Param('id') id: string) {
    return this.bannerService.remove(+id);
  }
}
